package com.simon.mengkou.ui.view.label;

import android.view.ViewGroup;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.ouertech.android.agm.lib.base.utils.UtilDevice;


/**
 * Created by gzjck on 2015/10/15.
 */
public class AnimateLabelView extends ViewGroup implements View.OnClickListener, View.OnTouchListener{
    public final static int STYLE_NONE_TEXT = 0;

    public final static int STYLE_ONE_TEXT_1 = 1;
    public final static int STYLE_ONE_TEXT_2 = 2;
    public final static int STYLE_ONE_TEXT_3 = 3;
    public final static int STYLE_ONE_TEXT_4 = 4;

    public final static int STYLE_TWO_TEXT_1 = 10;
    public final static int STYLE_TWO_TEXT_2 = 11;
    public final static int STYLE_TWO_TEXT_3 = 12;
    public final static int STYLE_TWO_TEXT_4 = 13;

    public final static int STYLE_THREE_TEXT_1 = 20;
    public final static int STYLE_THREE_TEXT_2 = 21;
    public final static int STYLE_THREE_TEXT_3 = 22;
    public final static int STYLE_THREE_TEXT_4 = 23;

    /**
     * view的宽
     */
    private int width;
    /**
     * view的高
     */
    private int height;

    /**
     * 当前的样式
     */
    private int currStyle = STYLE_NONE_TEXT;

    private String text1;
    private String text2;
    private String text3;

    private ImageView dot;

    int defaultTextsize = 18;
    int defaultTextPadding = 12;
    int defaultTextMarginBottom = 8;

    public AnimateLabelView(Context context) {
        this(context, null);
    }

    public AnimateLabelView(Context context, AttributeSet attrs) {
        super(context, attrs, 0);

        /**
         * 注意!!!这里一定要调用setWillNotDraw(false);
         * 否则不设置背景,viewgroup不会调用onDraw();
         */
        setWillNotDraw(false);

        initDot();

        info = new LabelInfo();
        float density = UtilDevice.getDevice(context).getDensity();
        defaultTextsize = Math.round(density* 12);
        defaultTextPadding = Math.round(density * 6);
        defaultTextMarginBottom = Math.round(density * 4);
        lineWidth = Math.round(density * 1);
    }


    /**
     * ######### Measure相关[BEGIN] #########
     */


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        measureCore(widthMeasureSpec, heightMeasureSpec);
    }

    private void measureCore(int widthMeasureSpec, int heightMeasureSpec) {
        //设置默认padding
        setPadding(20, 20, 20, 20);

        checkDisplayText();

        if(checkOrderStyle()){
            useOrderStyle();
        }

        switch(currStyle){
            case STYLE_NONE_TEXT:
                measureStyleNoText();
                break;

            case STYLE_ONE_TEXT_1:
                measureStyleOneText1();
                break;
            case STYLE_ONE_TEXT_2:
                measureStyleOneText2();
                break;
            case STYLE_ONE_TEXT_3:
                measureStyleOneText3();
                break;
            case STYLE_ONE_TEXT_4:
                measureStyleOneText4();
                break;

            //以下是两个text
            case STYLE_TWO_TEXT_1:
                measureStyleTwoText1();
                break;
            case STYLE_TWO_TEXT_2:
                measureStyleTwoText2();
                break;
            case STYLE_TWO_TEXT_3:
                measureStyleTwoText3();
                break;
            case STYLE_TWO_TEXT_4:
                measureStyleTwoText4();
                break;

            //以下是三个text
            case STYLE_THREE_TEXT_1:
                measureStyleThreeText1();
                break;
            case STYLE_THREE_TEXT_2:
                measureStyleThreeText2();
                break;
            case STYLE_THREE_TEXT_3:
                measureStyleThreeText3();
                break;
            case STYLE_THREE_TEXT_4:
                measureStyleThreeText4();
                break;
        }

        setMeasuredDimension(width, height);

        //保持point的位置
        setPointAt(pointAtX, pointAtY);

        //在改变view大小后,调用parent的layout,改变view在视图中的大小
        if(getLayoutParams()!=null){
            getLayoutParams().width = width;
            getLayoutParams().height = height;
        }
        if (getParent() != null) {
            getParent().requestLayout();
        }
    }
    /**
     * ######### Measure相关[END] #########
     */


    @Override
    public void onClick(View v) {
        if(centerRect.contains(lastX, lastY)){
            onCenterClick();
        }else{
            onOuterSideClick();
        }
    }

    /**
     * 判断是否点击中心
     * @param xInParent 父容器中的x坐标
     * @param yInParent 父容器中的y坐标
     * @return 是否点击中心
     */
    public boolean isCenterClick(float xInParent, float yInParent){
        return centerRect.contains((int)(xInParent - getX()), (int)(yInParent - getY()));
    }

    public  void onCenterClick(){
//        Toast.makeText(getContext(), "中心被点击", Toast.LENGTH_SHORT).show();

        changeStyle();
    }

    private OnOuterSideClickListener onOuterSideClickListener;
    public interface OnOuterSideClickListener{
        void onOuterClick(AnimateLabelView v);
    }

    public void setOnOuterSideClickListener(OnOuterSideClickListener l){
        this.onOuterSideClickListener = l;
    }

    public void onOuterSideClick(){
//        Toast.makeText(getContext(), "外围被点击", Toast.LENGTH_SHORT).show();

        if(this.onOuterSideClickListener != null){
            onOuterSideClickListener.onOuterClick(this);
        }
    }

    private void initDot(){
        dot = new ImageView(getContext());
        dot.setLayoutParams(new LayoutParams(2*r, 2*r));

        Bitmap bm = Bitmap.createBitmap(r*2, r*2, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(bm);
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        p.setColor(Color.WHITE);
        c.drawCircle(r, r, r, p);

        dot.setImageBitmap(bm);
        this.addView(dot);
    }

    /***
     * ### 显示效果[BEGIN] ###
     */
    private static final int ANIMATION_EACH_OFFSET = 400;
    private static final float ANIMATION_SCALE_MULTIPLE = 4.0f;
    public void wave() {
        AnimationSet as = new AnimationSet(true);
        ScaleAnimation sa = new ScaleAnimation(1f, ANIMATION_SCALE_MULTIPLE, 1f, ANIMATION_SCALE_MULTIPLE, ScaleAnimation.RELATIVE_TO_SELF,
                0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
        sa.setDuration(ANIMATION_EACH_OFFSET * 3);
        sa.setRepeatCount(5);// 设置循环
        AlphaAnimation aniAlp = new AlphaAnimation(1, 0.1f);
        aniAlp.setRepeatCount(5);// 设置循环
        as.setDuration(ANIMATION_EACH_OFFSET * 3);
        as.addAnimation(sa);
        as.addAnimation(aniAlp);
        dot.startAnimation(as);
    }

    public void alwaysWave(){
        AnimationSet as = new AnimationSet(true);
        ScaleAnimation sa = new ScaleAnimation(1f, ANIMATION_SCALE_MULTIPLE, 1f, ANIMATION_SCALE_MULTIPLE, ScaleAnimation.RELATIVE_TO_SELF,
                0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
        sa.setDuration(ANIMATION_EACH_OFFSET * 3);
        sa.setRepeatCount(Animation.INFINITE);// 设置循环
        AlphaAnimation aniAlp = new AlphaAnimation(1, 0.1f);
        aniAlp.setRepeatCount(Animation.INFINITE);// 设置循环
        as.setDuration(ANIMATION_EACH_OFFSET * 3);
        as.addAnimation(sa);
        as.addAnimation(aniAlp);
        dot.startAnimation(as);
    }

    public void show(){
        this.setVisibility(View.VISIBLE);
    }

    public void hide(){
        this.setVisibility(View.GONE);
    }
    /***
     * ### 显示效果[END] ###
     */


    public void setEmpty(){
        if(checkDisplayText()){
            setText1(null);
            setText2(null);
            setText3(null);

            updateViewAfterSetText();
        }
    }

    public void setText1(String text){
        this.text1 = text;

        checkDisplayText();
        updateViewAfterSetText();
    }

    public void setText2(String text){
        this.text2 = text;

        checkDisplayText();
        updateViewAfterSetText();
    }

    public void setText3(String text){
        this.text3 = text;

        checkDisplayText();
        updateViewAfterSetText();
    }

    public void updateViewAfterSetText(){
        //如果只是显示内容改变,也会改变视图的大小
        measureCore(currStyle, currStyle);
        invalidate();
    }

    /**
     * 外部调用setStyle指定的style
     */
    private int orderStyle = -1;
    public void orderStyle(int style){
        if(currStyle == orderStyle){
            //如果相同,不需要操作了
            return;
        }

        this.orderStyle = style;
    }

    private boolean checkOrderStyle(){
        if(orderStyle < 0){
            //没有预设style
            return false;
        }

        if(displayTextCount == 0 && orderStyle == STYLE_NONE_TEXT){
            return true;
        }else if(displayTextCount == 1){
            if(STYLE_ONE_TEXT_1 <= orderStyle && orderStyle <= STYLE_ONE_TEXT_4){
                return true;
            }
        }else if(displayTextCount == 2){
            if(STYLE_TWO_TEXT_1 <= orderStyle && orderStyle <= STYLE_TWO_TEXT_4){
                return true;
            }
        }else if(displayTextCount == 3){
            if(STYLE_THREE_TEXT_1 <= orderStyle && orderStyle <= STYLE_THREE_TEXT_4){
                return true;
            }
        }else{
            return false;
        }

        return false;
    }

    private void useOrderStyle(){
        this.currStyle = orderStyle;
        orderStyle = -1;
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int right, int b) {
        int dotLeft = centerX - r;
        int dotTop = centerY - r;
        int dotRight = dotLeft + 2*r;
        int dotBottom = dotTop + 2*r;
        dot.layout(dotLeft, dotTop, dotRight, dotBottom);
    }



    private void changeStyle(){
        if(currStyle == STYLE_NONE_TEXT){
            return;
        }

        if(STYLE_ONE_TEXT_1 <= currStyle && currStyle < STYLE_ONE_TEXT_4){
            currStyle++;
        }else if(currStyle == STYLE_ONE_TEXT_4){
            currStyle = STYLE_ONE_TEXT_1;
        }

        if(STYLE_TWO_TEXT_1 <= currStyle &&  currStyle < STYLE_TWO_TEXT_4){
            currStyle++;
        }else if(currStyle == STYLE_TWO_TEXT_4){
            currStyle = STYLE_TWO_TEXT_1;
        }

        if(STYLE_THREE_TEXT_1 <= currStyle &&  currStyle < STYLE_THREE_TEXT_4){
            currStyle++;
        }else if(currStyle == STYLE_THREE_TEXT_4){
            currStyle = STYLE_THREE_TEXT_1;
        }


        //调用onMeasure
        measureCore(currStyle, currStyle);
        //调用onDraw
        invalidate();
    }



    private int lastX;
    private int lastY;

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch(event.getAction()){
            case MotionEvent.ACTION_UP:
                lastX = (int)event.getX();
                lastY = (int)event.getY();
                break;
        }

        return false;
    }



    //显示的第一个字符串
    String displayText1;
    String displayText2;
    String displayText3;

    int displayTextCount = 0;

    /**
     * 查找应该显示的text,当所有的text为空时候返回false
     * @return 是否有该显示的字符?
     */
    private boolean checkDisplayText(){
        /**
         * 修改前显示的text数目
         */
        int oldDisplayTextCount = displayTextCount;

        displayTextCount = 0;
        displayText1 = null;
        displayText2 = null;
        displayText3 = null;

        if(!isNull(text1)){
            displayText1 = text1;
        }

        if(!isNull(text2)){
            if(displayText1==null){
                displayText1 = text2;
            }else{
                displayText2 = text2;
            }
        }

        if(!isNull(text3)){
            if(displayText1== null){
                displayText1 = text3;
            }else{
                if(displayText2 == null){
                    displayText2 = text3;
                }else{
                    displayText3 = text3;
                }
            }
        }

        if(displayText1 == null){
            displayTextCount = 0;
        }else if(displayText2 == null){
            displayTextCount = 1;
        }else if(displayText3 == null){
            displayTextCount = 2;
        }else{
            displayTextCount = 3;
        }

        //如果显示text数目改变
        if(displayTextCount != oldDisplayTextCount){
            onDisplayTextCountChange();
        }

        if(displayTextCount < 1){
            return false;
        }else{
            return true;
        }


    }

    /**
     * 当检测到显示text数目改变时:可能会导致:
     * <br>样式改变
     */
    private void onDisplayTextCountChange(){
        switch(displayTextCount){
            case 0:
                currStyle = STYLE_NONE_TEXT;
                break;
            case 1:
                currStyle = STYLE_ONE_TEXT_1;
                break;
            case 2:
                currStyle = STYLE_TWO_TEXT_1;
                break;
            case 3:
                currStyle = STYLE_THREE_TEXT_1;
                break;
        }

    }

    public class Point{
        public Point(){}

        public Point(int x, int y){
            this.x = x;
            this.y = y;
        }

        public int x;
        public int y;
    }

    private void setCenterRect(int centerX, int centerY){
        //中心范围int left, int top, int right, int bottom
        centerRect = new Rect(centerX - outerR, centerY - outerR, centerX + outerR, centerY + outerR);
    }


    /**
     * ############# 12种样式的具体Measure方法[BEGIN] #############
     */
    int centerX;
    int centerY;
    Rect centerRect;

    int text1Width;
    int text1Height;
    /**
     * text1的线条的折点
     */
    Point pointLine1Corner;
    /**
     * text1的线条的端点
     */
    Point pointLine1End;

    int text2Width;
    int text2Height;

    Point pointLine2Corner;
    Point pointLine2End;

    int text3Width;
    int text3Height;

    Point pointLine3Corner;
    Point pointLine3End;

    //测量的过程中,首先确定了多个关键的绘图的点
    private void measureStyleNoText(){
        centerX = getPaddingLeft() + outerR;
        centerY = getPaddingTop() + outerR;
        width = getPaddingLeft() + outerR * 2 + getPaddingRight();
        height = getPaddingTop() + outerR * 2 + getPaddingBottom();

        setCenterRect(centerX, centerY);
    }

    private void measureStyleOneText1(){
        text1Width = getTextWidth(displayText1);
        centerX = getPaddingLeft() + text1Width + slantLengthSqrt;
        centerY = getPaddingTop() + outerR;

        width = getPaddingLeft() + text1Width + slantLengthSqrt + outerR + getPaddingRight();
        height = getPaddingTop() + outerR + slantLengthSqrt + getPaddingBottom();

        pointLine1Corner = new Point();
        pointLine1Corner.x = centerX - slantLengthSqrt;
        pointLine1Corner.y = centerY + slantLengthSqrt;

        pointLine1End = new Point();
        pointLine1End.x = pointLine1Corner.x - text1Width;
        pointLine1End.y = pointLine1Corner.y;

        setCenterRect(centerX, centerY);
    }

    private void measureStyleOneText2(){
        text1Width = getTextWidth(displayText1);
        centerX = getPaddingLeft() + outerR;
        centerY = getPaddingTop() + outerR;

        width = getPaddingLeft() + text1Width + slantLengthSqrt + outerR + getPaddingRight();
        height = getPaddingTop() + outerR + slantLengthSqrt + getPaddingBottom();

        pointLine1Corner = new Point();
        pointLine1Corner.x = centerX + slantLengthSqrt;
        pointLine1Corner.y = centerY + slantLengthSqrt;

        pointLine1End = new Point();
        pointLine1End.x = pointLine1Corner.x + text1Width;
        pointLine1End.y = pointLine1Corner.y;

        setCenterRect(centerX, centerY);
    }



    private void measureStyleOneText3(){
        text1Width = getTextWidth(displayText1);
        text1Height = getTextHeight(displayText1);

        centerX = getPaddingLeft() + text1Width + outerR;
        centerY = getPaddingTop() + text1Height;

        width = centerX + outerR + getPaddingRight();
        height = centerY + outerR + getPaddingBottom();

        pointLine1End = new Point();
        pointLine1End.x = centerX - outerR - text1Width;
        pointLine1End.y = centerY;

        setCenterRect(centerX, centerY);
    }

    private void measureStyleOneText4(){
        text1Width = getTextWidth(displayText1);
        text1Height = getTextHeight(displayText1);

        centerX = getPaddingLeft() + outerR;
        centerY = getPaddingTop() + text1Height;

        width = centerX + outerR + text1Width + getPaddingRight();
        height = centerY + outerR + getPaddingBottom();

        pointLine1End = new Point();
        pointLine1End.x = centerX + outerR + text1Width;
        pointLine1End.y = centerY;

        setCenterRect(centerX, centerY);
    }

    //以下是两个text
    private void measureStyleTwoText1(){
        text1Width = getTextWidth(displayText1);
        text1Height = getTextHeight(displayText1);

        text2Width = getTextWidth(displayText2);
        text2Height = getTextHeight(displayText2);

        height = getPaddingTop() + text1Height + slantLengthSqrt * 2 + getPaddingBottom();
        width = getPaddingLeft() + Math.max(text1Width, text2Width) + slantLengthSqrt + outerR + getPaddingRight();

        centerX = getPaddingLeft() + Math.max(text1Width, text2Width) + slantLengthSqrt;
        centerY = getPaddingTop() + text1Height + slantLengthSqrt;


        pointLine1Corner = new Point();
        pointLine1Corner.x = centerX - slantLengthSqrt;
        pointLine1Corner.y = centerY - slantLengthSqrt;

        pointLine1End = new Point();
        pointLine1End.x = pointLine1Corner.x - text1Width;
        pointLine1End.y = pointLine1Corner.y;

        pointLine2Corner = new Point();
        pointLine2Corner.x = centerX - slantLengthSqrt;
        pointLine2Corner.y = centerY + slantLengthSqrt;

        pointLine2End = new Point();
        pointLine2End.x = pointLine2Corner.x - text2Width;
        pointLine2End.y = pointLine2Corner.y;

        setCenterRect(centerX, centerY);
    }

    private void measureStyleTwoText2(){
        text1Width = getTextWidth(displayText1);
        text1Height = getTextHeight(displayText1);

        text2Width = getTextWidth(displayText2);
        text2Height = getTextHeight(displayText2);

        height = getPaddingTop() + text1Height + slantLengthSqrt * 2 + getPaddingBottom();
        width = getPaddingLeft() + Math.max(text1Width, text2Width) + slantLengthSqrt + outerR + getPaddingRight();

        centerX = getPaddingLeft() + outerR;
        centerY = getPaddingTop() + text1Height + slantLengthSqrt;


        pointLine1Corner = new Point();
        pointLine1Corner.x = centerX + slantLengthSqrt;
        pointLine1Corner.y = centerY - slantLengthSqrt;

        pointLine1End = new Point();
        pointLine1End.x = pointLine1Corner.x + text1Width;
        pointLine1End.y = pointLine1Corner.y;

        pointLine2Corner = new Point();
        pointLine2Corner.x = centerX + slantLengthSqrt;
        pointLine2Corner.y = centerY + slantLengthSqrt;

        pointLine2End = new Point();
        pointLine2End.x = pointLine2Corner.x + text2Width;
        pointLine2End.y = pointLine2Corner.y;

        setCenterRect(centerX, centerY);
    }

    private void measureStyleTwoText3(){
        text1Width = getTextWidth(displayText1);
        text1Height = getTextHeight(displayText1);

        text2Width = getTextWidth(displayText2);
        text2Height = getTextHeight(displayText2);

        height = getPaddingTop() + text1Height + slantLength * 2 + getPaddingBottom();
        width = getPaddingLeft() + Math.max(text1Width, text2Width) + outerR + getPaddingRight();

        centerX = getPaddingLeft() + Math.max(text1Width, text2Width);
        centerY = getPaddingTop() + text1Height + slantLength;


        pointLine1Corner = new Point();
        pointLine1Corner.x = centerX;
        pointLine1Corner.y = centerY - slantLength;

        pointLine1End = new Point();
        pointLine1End.x = pointLine1Corner.x - text1Width;
        pointLine1End.y = pointLine1Corner.y;

        pointLine2Corner = new Point();
        pointLine2Corner.x = centerX ;
        pointLine2Corner.y = centerY + slantLength;

        pointLine2End = new Point();
        pointLine2End.x = pointLine2Corner.x - text2Width;
        pointLine2End.y = pointLine2Corner.y;

        setCenterRect(centerX, centerY);
    }

    private void measureStyleTwoText4(){
        text1Width = getTextWidth(displayText1);
        text1Height = getTextHeight(displayText1);

        text2Width = getTextWidth(displayText2);
        text2Height = getTextHeight(displayText2);

        height = getPaddingTop() + text1Height + slantLength * 2 + getPaddingBottom();
        width = getPaddingLeft() + Math.max(text1Width, text2Width) + outerR + getPaddingRight();

        centerX = getPaddingLeft() + outerR;
        centerY = getPaddingTop() + text1Height + slantLength;


        pointLine1Corner = new Point();
        pointLine1Corner.x = centerX;
        pointLine1Corner.y = centerY - slantLength;

        pointLine1End = new Point();
        pointLine1End.x = pointLine1Corner.x + text1Width;
        pointLine1End.y = pointLine1Corner.y;

        pointLine2Corner = new Point();
        pointLine2Corner.x = centerX ;
        pointLine2Corner.y = centerY + slantLength;

        pointLine2End = new Point();
        pointLine2End.x = pointLine2Corner.x + text2Width;
        pointLine2End.y = pointLine2Corner.y;

        setCenterRect(centerX, centerY);
    }

    //以下是三个text
    private void measureStyleThreeText1(){
        text1Width = getTextWidth(displayText1);
        text1Height = getTextHeight(displayText1);

        text2Width = getTextWidth(displayText2);
        text2Height = getTextHeight(displayText2);

        text3Width = getTextWidth(displayText3);
        text3Height = getTextHeight(displayText3);

        height = getPaddingTop() + text1Height + slantLengthSqrt * 2 + getPaddingBottom();
        width = getPaddingLeft() + Math.max(text1Width, text3Width) + slantLengthSqrt * 2 + text2Width + getPaddingRight();

        centerX = getPaddingLeft() + Math.max(text1Width, text3Width) + slantLengthSqrt;
        centerY = getPaddingTop() + text1Height + slantLengthSqrt;


        pointLine1Corner = new Point();
        pointLine1Corner.x = centerX - slantLengthSqrt;
        pointLine1Corner.y = centerY - slantLengthSqrt;

        pointLine1End = new Point();
        pointLine1End.x = pointLine1Corner.x - text1Width;
        pointLine1End.y = pointLine1Corner.y;

        pointLine2Corner = new Point();
        pointLine2Corner.x = centerX + slantLengthSqrt;
        pointLine2Corner.y = centerY + slantLengthSqrt;

        pointLine2End = new Point();
        pointLine2End.x = pointLine2Corner.x + text2Width;
        pointLine2End.y = pointLine2Corner.y;

        pointLine3Corner = new Point();
        pointLine3Corner.x = centerX - slantLengthSqrt;
        pointLine3Corner.y = centerY + slantLengthSqrt;

        pointLine3End = new Point();
        pointLine3End.x = pointLine3Corner.x - text3Width;
        pointLine3End.y = pointLine3Corner.y;

        setCenterRect(centerX, centerY);
    }

    private void measureStyleThreeText2(){
        text1Width = getTextWidth(displayText1);
        text1Height = getTextHeight(displayText1);

        text2Width = getTextWidth(displayText2);
        text2Height = getTextHeight(displayText2);

        text3Width = getTextWidth(displayText3);
        text3Height = getTextHeight(displayText3);

        height = getPaddingTop() + text1Height + slantLengthSqrt * 2 + getPaddingBottom();
        width = getPaddingLeft() + Math.max(text1Width, text3Width) + slantLengthSqrt * 2 + text2Width + getPaddingRight();

        centerX = getPaddingLeft() + text2Width + slantLengthSqrt;
        centerY = getPaddingTop() + text1Height + slantLengthSqrt;


        pointLine1Corner = new Point();
        pointLine1Corner.x = centerX + slantLengthSqrt;
        pointLine1Corner.y = centerY - slantLengthSqrt;

        pointLine1End = new Point();
        pointLine1End.x = pointLine1Corner.x + text1Width;
        pointLine1End.y = pointLine1Corner.y;

        pointLine2Corner = new Point();
        pointLine2Corner.x = centerX - slantLengthSqrt;
        pointLine2Corner.y = centerY + slantLengthSqrt;

        pointLine2End = new Point();
        pointLine2End.x = pointLine2Corner.x - text2Width;
        pointLine2End.y = pointLine2Corner.y;

        pointLine3Corner = new Point();
        pointLine3Corner.x = centerX + slantLengthSqrt;
        pointLine3Corner.y = centerY + slantLengthSqrt;

        pointLine3End = new Point();
        pointLine3End.x = pointLine3Corner.x + text3Width;
        pointLine3End.y = pointLine3Corner.y;

        setCenterRect(centerX, centerY);
    }

    private void measureStyleThreeText3(){
        text1Width = getTextWidth(displayText1);
        text1Height = getTextHeight(displayText1);

        text2Width = getTextWidth(displayText2);
        text2Height = getTextHeight(displayText2);

        text3Width = getTextWidth(displayText3);
        text3Height = getTextHeight(displayText3);

        int maxTextWidth = Math.max(text1Width, Math.max(text2Width, text3Width));

        height = getPaddingTop() + text3Height + slantLength * 2 + getPaddingBottom();
        width = getPaddingLeft() + maxTextWidth + outerR + getPaddingRight();

        centerX = getPaddingLeft() + maxTextWidth;
        centerY = getPaddingTop() + text3Height + slantLength;

        pointLine1Corner = new Point();
        pointLine1Corner.x = centerX;
        pointLine1Corner.y = centerY + slantLength;

        pointLine1End = new Point();
        pointLine1End.x = pointLine1Corner.x - text1Width;
        pointLine1End.y = pointLine1Corner.y;

        pointLine2End = new Point();
        pointLine2End.x = centerX - text2Width;
        pointLine2End.y = centerY;

        pointLine3Corner = new Point();
        pointLine3Corner.x = centerX;
        pointLine3Corner.y = centerY - slantLength;

        pointLine3End = new Point();
        pointLine3End.x = pointLine3Corner.x - text3Width;
        pointLine3End.y = pointLine3Corner.y;

        setCenterRect(centerX, centerY);
    }

    private void measureStyleThreeText4(){
        text1Width = getTextWidth(displayText1);
        text1Height = getTextHeight(displayText1);

        text2Width = getTextWidth(displayText2);
        text2Height = getTextHeight(displayText2);

        text3Width = getTextWidth(displayText3);
        text3Height = getTextHeight(displayText3);

        int maxTextWidth = Math.max(text1Width, Math.max(text2Width, text3Width));

        height = getPaddingTop() + text3Height + slantLength * 2 + getPaddingBottom();
        width = getPaddingLeft() + maxTextWidth + outerR + getPaddingRight();

        centerX = getPaddingLeft() + outerR;
        centerY = getPaddingTop() + text3Height + slantLength;

        pointLine1Corner = new Point();
        pointLine1Corner.x = centerX;
        pointLine1Corner.y = centerY + slantLength;

        pointLine1End = new Point();
        pointLine1End.x = pointLine1Corner.x + text1Width;
        pointLine1End.y = pointLine1Corner.y;

        pointLine2End = new Point();
        pointLine2End.x = centerX + text2Width;
        pointLine2End.y = centerY;

        pointLine3Corner = new Point();
        pointLine3Corner.x = centerX;
        pointLine3Corner.y = centerY - slantLength;

        pointLine3End = new Point();
        pointLine3End.x = pointLine3Corner.x + text3Width;
        pointLine3End.y = pointLine3Corner.y;

        setCenterRect(centerX, centerY);
    }
    /**
     * ############# 12种样式的具体Measure方法[END] #############
     */



    /**
     * ############# Draw相关[BEGIN] #############
     */

    /**
     * 白色实心圆的半径
     */
    int r = 8;
    /**
     * 外圈的圆半径
     */
    int outerR = (int)(1.5 * r);
    int lineWidth = 2;
    /**斜线L1的长度是5*r*/
    int slantLength = 10 * r;
    /**斜线在XY轴上的投影长度*/
    int slantLengthSqrt = (int)(slantLength / Math.sqrt(2));

    @Override
    protected void onDraw(Canvas canvas) {
        switch(currStyle){
            case STYLE_NONE_TEXT:
                drawNoText(canvas);
                break;

            case STYLE_ONE_TEXT_1:
                drawOneText1(canvas);
                break;
            case STYLE_ONE_TEXT_2:
                drawOneText2(canvas);
                break;
            case STYLE_ONE_TEXT_3:
                drawOneText3(canvas);
                break;
            case STYLE_ONE_TEXT_4:
                drawOneText4(canvas);
                break;

            //以下是两个text的
            case STYLE_TWO_TEXT_1:
                drawTwoText1(canvas);
                break;
            case STYLE_TWO_TEXT_2:
                drawTwoText2(canvas);
                break;
            case STYLE_TWO_TEXT_3:
                drawTwoText3(canvas);
                break;
            case STYLE_TWO_TEXT_4:
                drawTwoText4(canvas);
                break;

            //以下是三个text的
            case STYLE_THREE_TEXT_1:
                drawThreeText1(canvas);
                break;
            case STYLE_THREE_TEXT_2:
                drawThreeText2(canvas);
                break;
            case STYLE_THREE_TEXT_3:
                drawThreeText3(canvas);
                break;
            case STYLE_THREE_TEXT_4:
                drawThreeText4(canvas);
                break;

        }


    }

    /**
     * 返回在父容器中pointAt
     * @return
     */
    private Point getPointAt(){
        int x = (int)getX() + centerX;
        int y = (int)getY() + centerY;

        Log.d("pointAt:", x + "/" + y);

        //???10.22屏蔽
        //setPointAt(pointAtX, pointAtY);
        return new Point(x, y);
    }

    /**
     * 中心指示的位置(在父容器中的像素坐标)
     */
    public int pointAtX, pointAtY;
    public void setPointAt(final float x, final float y){
        pointAtX = (int)x;
        pointAtY = (int)y;

        info.pxX = x;
        info.pxY = y;

        //10.22修改:不需要用post
//        post(new Runnable() {
//            @Override
//            public void run() {
//                int centerXinParent = (int)getX() + centerX;
//                int centerYinParent = (int)getY() + centerY;
//
//                setX(getX() + x - centerXinParent);
//                setY(getY() + y - centerYinParent);
//
//            }
//        });
        int centerXinParent = (int)getX() + centerX;
        int centerYinParent = (int)getY() + centerY;

        //因为添加了pcX, pcY,更新位置后需要更新
        updatePcXandPcY(centerXinParent, centerYinParent);

        setX(getX() + x - centerXinParent);
        setY(getY() + y - centerYinParent);
    }

    /**
     * 因为添加了pcX, pcY,更新位置后需要更新
     * @param pxX
     * @param pxY
     */
    private void updatePcXandPcY(float pxX, float pxY){
        if(getParent()!=null){
            float pw = ((ViewGroup)getParent()).getWidth();
            float ph = ((ViewGroup)getParent()).getHeight();

            if(pw > 0 && ph > 0){
                info.pcX = pxX/pw;
                info.pcY = pxY/ph;
            }
        }
    }
    /**
     * 优先使用比例的位置
     * @param xpc 水平方向上的百分比
     * @param ypc 垂直方向上的百分比
     */
    public void setPointAtPercent(final float xpc, final float ypc){
        info.pcX = xpc;
        info.pcY = ypc;

        post(new PointAtPercentRunnable(xpc, ypc));
    }

    class PointAtPercentRunnable implements Runnable{
        private float xpc, ypc;

        public PointAtPercentRunnable(float xpc, float ypc){
            this.xpc = xpc;
            this.ypc = ypc;
        }

        @Override
        public void run() {
            if(getParent()==null){
                return;
            }

            if(getParent() instanceof RelativeLayout){
                RelativeLayout p = (RelativeLayout)getParent();

                float pxX = p.getWidth()*xpc;
                float pxY = p.getHeight()*ypc;

                setPointAt(pxX, pxY);
            }
        }
    }

    public void addTo(ViewGroup container, int left, int top){
        container.addView(this);
        setPointAt(left, top);
    }

    public int outerCircleColor = Color.LTGRAY;
    public int centerColor = Color.WHITE;
    public int lineColor = Color.WHITE;
    public int textColor = Color.WHITE;

    private void drawNoText(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);
    }

    private void drawOneText1(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //单线样式1:左下斜线__/
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左下斜线
        canvas.drawLine(centerX, centerY, pointLine1Corner.x,  pointLine1Corner.y, p);
        //左下横线
        canvas.drawLine(pointLine1Corner.x, pointLine1Corner.y, pointLine1End.x, pointLine1End.y, p);
        //左下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);

        canvas.drawText(displayText1, pointLine1End.x + defaultTextPadding, pointLine1Corner.y - defaultTextMarginBottom, p);
    }

    private void drawOneText2(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //单线样式2:右下斜线__/
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //右下斜线
        canvas.drawLine(centerX, centerY, pointLine1Corner.x, pointLine1Corner.y, p);
        //右下横线
        canvas.drawLine(pointLine1Corner.x, pointLine1Corner.y, pointLine1End.x, pointLine1End.y, p);
        //右下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText1, pointLine1Corner.x + defaultTextPadding, pointLine1Corner.y - defaultTextMarginBottom, p);
    }


    private void drawOneText3(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //单线样式2:右下斜线__/
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左线
        canvas.drawLine(centerX, centerY, pointLine1End.x,  pointLine1End.y, p);
        //文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText1, pointLine1End.x + defaultTextPadding, pointLine1End.y - defaultTextMarginBottom, p);
    }

    private void drawOneText4(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //单线样式2:右下斜线__/
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左线
        canvas.drawLine(centerX, centerY, pointLine1End.x,  pointLine1End.y, p);
        //文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText1, centerX + outerR + defaultTextPadding, pointLine1End.y - defaultTextMarginBottom, p);
    }

    private void drawTwoText1(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //text1
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左上斜线
        canvas.drawLine(centerX, centerY, pointLine1Corner.x, pointLine1Corner.y, p);
        //左上横线
        canvas.drawLine(pointLine1Corner.x, pointLine1Corner.y, pointLine1End.x, pointLine1End.y, p);
        //左上文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText1, pointLine1End.x + defaultTextPadding, pointLine1End.y - defaultTextMarginBottom, p);

        //text2
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左下斜线
        canvas.drawLine(centerX, centerY, pointLine2Corner.x, pointLine2Corner.y, p);
        //左下横线
        canvas.drawLine(pointLine2Corner.x, pointLine2Corner.y, pointLine2End.x, pointLine2End.y, p);
        //左下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText2, pointLine2End.x + defaultTextPadding, pointLine2End.y - defaultTextMarginBottom, p);
    }

    private void drawTwoText2(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //text1
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //右上斜线
        canvas.drawLine(centerX, centerY, pointLine1Corner.x, pointLine1Corner.y, p);
        //右上横线
        canvas.drawLine(pointLine1Corner.x, pointLine1Corner.y, pointLine1End.x, pointLine1End.y, p);
        //右上文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText1, pointLine1Corner.x + defaultTextPadding, pointLine1Corner.y - defaultTextMarginBottom, p);

        //text2
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左下斜线
        canvas.drawLine(centerX, centerY, pointLine2Corner.x, pointLine2Corner.y, p);
        //左下横线
        canvas.drawLine(pointLine2Corner.x, pointLine2Corner.y, pointLine2End.x, pointLine2End.y, p);
        //左下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText2, pointLine2Corner.x + defaultTextPadding, pointLine2Corner.y - defaultTextMarginBottom, p);
    }

    private void drawTwoText3(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //text1
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左上斜线
        canvas.drawLine(centerX, centerY, pointLine1Corner.x, pointLine1Corner.y, p);
        //左上横线
        canvas.drawLine(pointLine1Corner.x, pointLine1Corner.y, pointLine1End.x, pointLine1End.y, p);
        //左上文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText1, pointLine1End.x + defaultTextPadding, pointLine1End.y - defaultTextMarginBottom, p);

        //text2
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左下斜线
        canvas.drawLine(centerX, centerY, pointLine2Corner.x, pointLine2Corner.y, p);
        //左下横线
        canvas.drawLine(pointLine2Corner.x, pointLine2Corner.y, pointLine2End.x, pointLine2End.y, p);
        //左下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText2, pointLine2End.x + defaultTextPadding, pointLine2End.y - defaultTextMarginBottom, p);
    }

    private void drawTwoText4(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //text1
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //右上斜线
        canvas.drawLine(centerX, centerY, pointLine1Corner.x, pointLine1Corner.y, p);
        //右上横线
        canvas.drawLine(pointLine1Corner.x, pointLine1Corner.y, pointLine1End.x, pointLine1End.y, p);
        //右上文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText1, pointLine1Corner.x + defaultTextPadding, pointLine1Corner.y - defaultTextMarginBottom, p);

        //text2
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左下斜线
        canvas.drawLine(centerX, centerY, pointLine2Corner.x, pointLine2Corner.y, p);
        //左下横线
        canvas.drawLine(pointLine2Corner.x, pointLine2Corner.y, pointLine2End.x, pointLine2End.y, p);
        //左下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText2, pointLine2Corner.x + defaultTextPadding, pointLine2Corner.y - defaultTextMarginBottom, p);
    }

    private void drawThreeText1(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //text1
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左上斜线
        canvas.drawLine(centerX, centerY, pointLine1Corner.x, pointLine1Corner.y, p);
        //左上横线
        canvas.drawLine(pointLine1Corner.x, pointLine1Corner.y, pointLine1End.x, pointLine1End.y, p);
        //左上文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText1, pointLine1End.x + defaultTextPadding, pointLine1End.y - defaultTextMarginBottom, p);

        //text2
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //右下斜线
        canvas.drawLine(centerX, centerY, pointLine2Corner.x, pointLine2Corner.y, p);
        //右下横线
        canvas.drawLine(pointLine2Corner.x, pointLine2Corner.y, pointLine2End.x, pointLine2End.y, p);
        //右下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText2, pointLine2Corner.x + defaultTextPadding, pointLine2Corner.y - defaultTextMarginBottom, p);

        //text3
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左下斜线
        canvas.drawLine(centerX, centerY, pointLine3Corner.x, pointLine3Corner.y, p);
        //左下横线
        canvas.drawLine(pointLine3Corner.x, pointLine3Corner.y, pointLine3End.x, pointLine3End.y, p);
        //左下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText3, pointLine3End.x + defaultTextPadding, pointLine3End.y - defaultTextMarginBottom, p);
    }

    private void drawThreeText2(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //text1
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //右上斜线
        canvas.drawLine(centerX, centerY, pointLine1Corner.x, pointLine1Corner.y, p);
        //右上横线
        canvas.drawLine(pointLine1Corner.x, pointLine1Corner.y, pointLine1End.x, pointLine1End.y, p);
        //右上文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText1, pointLine1Corner.x + defaultTextPadding, pointLine1End.y - defaultTextMarginBottom, p);

        //text2
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左下斜线
        canvas.drawLine(centerX, centerY, pointLine2Corner.x, pointLine2Corner.y, p);
        //左下横线
        canvas.drawLine(pointLine2Corner.x, pointLine2Corner.y, pointLine2End.x, pointLine2End.y, p);
        //左下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText2, pointLine2End.x + defaultTextPadding, pointLine2End.y - defaultTextMarginBottom, p);

        //text3
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //右下斜线
        canvas.drawLine(centerX, centerY, pointLine3Corner.x, pointLine3Corner.y, p);
        //右下横线
        canvas.drawLine(pointLine3Corner.x, pointLine3Corner.y, pointLine3End.x, pointLine3End.y, p);
        //右下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText3, pointLine3Corner.x + defaultTextPadding, pointLine3End.y - defaultTextMarginBottom, p);
    }

    private void drawThreeText3(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //text1
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左下斜线
        canvas.drawLine(centerX, centerY, pointLine1Corner.x, pointLine1Corner.y, p);
        //左下横线
        canvas.drawLine(pointLine1Corner.x, pointLine1Corner.y, pointLine1End.x, pointLine1End.y, p);
        //左下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText1, pointLine1End.x + defaultTextPadding, pointLine1End.y - defaultTextMarginBottom, p);

        //text2
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左横线
        canvas.drawLine(centerX, centerY, pointLine2End.x, pointLine2End.y, p);
        //左文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText2, pointLine2End.x + defaultTextPadding, pointLine2End.y - defaultTextMarginBottom, p);

        //text3
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //左上斜线
        canvas.drawLine(centerX, centerY, pointLine3Corner.x, pointLine3Corner.y, p);
        //左上横线
        canvas.drawLine(pointLine3Corner.x, pointLine3Corner.y, pointLine3End.x, pointLine3End.y, p);
        //左上文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText3, pointLine3End.x + defaultTextPadding, pointLine3End.y - defaultTextMarginBottom, p);
    }

    private void drawThreeText4(Canvas canvas){
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setStrokeWidth(r);
        //外圆
        p.setColor(outerCircleColor);
        canvas.drawCircle(centerX, centerY, outerR, p);

        //内圆
        p.setColor(centerColor);
        canvas.drawCircle(centerX, centerY, r, p);

        //text1
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //右下斜线
        canvas.drawLine(centerX, centerY, pointLine1Corner.x, pointLine1Corner.y, p);
        //右下横线
        canvas.drawLine(pointLine1Corner.x, pointLine1Corner.y, pointLine1End.x, pointLine1End.y, p);
        //右下文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText1, pointLine1Corner.x + defaultTextPadding, pointLine1Corner.y - defaultTextMarginBottom, p);

        //text2
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //右横线
        canvas.drawLine(centerX, centerY, pointLine2End.x, pointLine2End.y, p);
        //右文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText2, centerX + defaultTextPadding, centerY - defaultTextMarginBottom, p);

        //text3
        p.setStrokeWidth(lineWidth);
        p.setColor(lineColor);
        //右上斜线
        canvas.drawLine(centerX, centerY, pointLine3Corner.x, pointLine3Corner.y, p);
        //右上横线
        canvas.drawLine(pointLine3Corner.x, pointLine3Corner.y, pointLine3End.x, pointLine3End.y, p);
        //右上文字
        p.setColor(textColor);
        p.setTextSize(defaultTextsize);
        canvas.drawText(displayText3, pointLine3Corner.x + defaultTextPadding, pointLine3Corner.y - defaultTextMarginBottom, p);
    }

    /**
     * ############# Draw相关[END] #############
     */

    private boolean isNull(String text){
        if(text == null || "".equals(text.trim())){
            return true;
        }

        return false;
    }



    /**
     * 返回text的宽度+左右padding
     * @param text
     * @return
     */
    private int getTextWidth(String text){
        if(isNull(text)){
            return defaultTextPadding * 2;
        }

        Rect rect = new Rect();
        Paint p = new Paint();
        p.setTextSize(defaultTextsize);
        p.getTextBounds(text, 0, text.length(), rect);
        float textWidth = rect.width();
        int desired = (int) (defaultTextPadding + textWidth + defaultTextPadding);
        return desired;
    }

    /**
     * 返回text的高度+默认离底部的距离
     * @param text
     * @return
     */
    private int getTextHeight(String text){
        Rect rect = new Rect();
        Paint p = new Paint();
        p.setTextSize(defaultTextsize);
        p.getTextBounds(text, 0, text.length(), rect);
        float textHeight = rect.height();
        int desired = (int) (textHeight + defaultTextMarginBottom);
        return desired;
    }

    public Point getCenter(){
        return new Point(centerX, centerY);
    }


    /**
     * ######### 使用LabelInfo相关[BEGIN] #########
     */
    private LabelInfo info;
    /**
     * 直接设置
     */
    public void setLabelInfo(LabelInfo info){
        if(info==null){
            return;
        }
        this.info = info;

        //保留一下会改变的pxX/Y
        float pxX = info.pxX;
        float pxY = info.pxY;

        /**
         * settext会改变info的pxX
         */
        setText1(combineTitleNInput(info.title1Text, info.input1Text));
        setText2(combineTitleNInput(info.title2Text, info.input2Text));
        setText3(combineTitleNInput(info.title3Text, info.input3Text));

        if(info.pcX > 0 && info.pcY > 0){
            setPointAtPercent(info.pcX, info.pcY);
        }else if(pxX > 0 && pxY > 0){
            setPointAt(pxX, pxY);
        }

    }

    public String combineTitleNInput(String t, String i){
        if(isNull(t) && isNull(i)){
            return null;
        }else{
            if(isNull(t)){
                return i;
            }else if(isNull(i)){
                return t;
            }else{
                return t + " " + i;
            }
        }
    }

    public LabelInfo getLabelInfo(){
        info.pxX = getPointAt().x;
        info.pxY = getPointAt().y;
        return info;
    }

    /**
     * ######### 使用LabelInfo相关[END] #########
     */
}
